package com.pinganfu.tesla.iwallet.app;

import android.app.Application;
import android.content.pm.PackageInfo;
import android.content.res.Configuration;

import com.pinganfu.tesla.iwallet.bean.UserPref;
import com.pinganfu.tesla.iwallet.session.SessionManager;
import com.pinganfu.tesla.iwallet.util.LogUtil;
import com.pinganfu.tesla.iwallet.util.TeslaUtil;

public class ClientApp extends Application {

	private SessionManager mSessionMgr;

	public void onCreate() {
		super.onCreate();
		mSessionMgr = SessionManager.getInstance();

		initSystemInfo();

		initUserPref();
	}

	private void initSystemInfo() {
		try {
			PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), 0);
			mSessionMgr.setAppVerCode(info.versionCode);
			mSessionMgr.setAppVerName(info.versionName);
			mSessionMgr.setMobileNo(TeslaUtil.getCurrentMobileNo(getBaseContext()));
		} catch (Exception e) {
			LogUtil.e(e.getMessage(), e);
		}
	}

	private void initUserPref() {
		UserPref userPref = new UserPref();
		userPref.setMobileNo(mSessionMgr.getMobileNo());
		userPref.setCertName("汤建华");
		userPref.setNickName("shmp2005");
		mSessionMgr.setUserPref(userPref);
	}

	public void onConfigurationChanged(Configuration newConfig) {
		super.onConfigurationChanged(newConfig);
	}

	public void onLowMemory() {
		super.onLowMemory();
	}
}
